//package org.activoricordi.app.snippet
package edu.ucdavis.fiehnlab.alchemy.alchemyAdmin.snippet

/**
 * Created with IntelliJ IDEA.
 * User: naru
 * Date: 3/28/13
 * Time: 4:43 PM
 * To change this template use File | Settings | File Templates.
 */
import net.liftweb.common.{Box,Full,Empty,Failure,ParamFailure}
import net.liftweb._
import  edu.ucdavis.fiehnlab.alchemy.alchemyAdmin.model._
import util._
import Helpers._
import http._
import SHtml._
import S._
import mapper._
import util._
import Helpers._


import scala.xml.{NodeSeq, Text}

class DeleteMethod {

  /**
   * get the id of current Method
   */
  var id = S.param("id") openOr ""
  /**
   * find the Method by id
   */
  var method = try {
    Method.findByKey(id.toLong)
  } catch {
    case e:NumberFormatException => Empty
  }

  def delete (html: NodeSeq): NodeSeq ={

    method map ({ i =>

    /**
     * delete Method function
     */
      def deleteItem() :Unit = {
        i.delete_!
        S.redirectTo("/method/list")
      }

      /**
       * show Method for verify Delete
       */
      bind("method", html,
        "name" -> i.name,
        "riWindow" -> i.riWindow,
        "massWindow" -> i.massWindow,
        "description" -> i.description,
        "submit" ->submit("Delete", deleteItem )
      )

      /**
       * if there is no Method or Empty record
       */
    }) openOr Text("Invalid Method")
  }

}
